package com.puyuba.puyuba.utils;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hjq.toast.ToastUtils;
import com.netease.nis.quicklogin.helper.UnifyUiConfig;
import com.netease.nis.quicklogin.utils.LoginUiHelper;
import com.puyuba.puyuba.view.activity.LoginActivity;
import com.pyb.java.commonutil.ToastHelper;
import com.pyb.java.commonutil.utils.ScreenUtils;
import com.pyb.java.network.NetBaseApi;
import com.pyb.module.ogin.R;

/**
 * Created by hzhuqi on 2019/12/31
 */
public class QuickLoginUiConfig {
    private static boolean isselect;

    public static boolean getIsAgree(){
        return isselect;
    }
    public static void setIsAgree(boolean isselect2){
        isselect = isselect2;
    }
    public static UnifyUiConfig getUiConfig(final Context context) {

        ImageView isagree = new ImageView(context);
        isagree.setImageResource(R.drawable.icon_unselect);
        isagree.setScaleType(ImageView.ScaleType.FIT_XY);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        layoutParams.width = ScreenUtils.getInstance().dip2px(16);
        layoutParams.height = ScreenUtils.getInstance().dip2px(16);
        layoutParams.setMargins(ScreenUtils.getInstance()
                .dip2px(20), 0, 0, ScreenUtils.getInstance().dip2px(40));
        isagree.setLayoutParams(layoutParams);

        TextView textView = new TextView(context);
        textView.setText("其他号码登录");
        textView.setTextColor(context.getColor(R.color.login_color_d6dadf));
        textView.setTextSize((float)14);
        textView.setGravity(Gravity.CENTER);
        textView.setBackgroundResource(R.drawable.login_shape_line_grey_dp30);
        textView.setWidth((int) ScreenUtils.dpToPixel(context,300));
        textView.setHeight((int) ScreenUtils.dpToPixel(context,45));
        RelativeLayout.LayoutParams textlayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        textlayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
//        textlayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        textlayoutParams.setMargins(0, ScreenUtils.getInstance()
                .dip2px(360), 0, 0);
        textView.setLayoutParams(textlayoutParams);

//        LayoutInflater inflater = LayoutInflater.from(context);
//        RelativeLayout otherLoginRel = (RelativeLayout) inflater.inflate(R.layout.custom_other_login, null);
//        RelativeLayout.LayoutParams layoutParamsOther = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
//        layoutParamsOther.setMargins(0, 0, 0, Utils.dip2px(context, 130));
//        layoutParamsOther.addRule(RelativeLayout.CENTER_HORIZONTAL);
//        layoutParamsOther.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
//        otherLoginRel.setLayoutParams(layoutParamsOther);
//        ImageView wx = otherLoginRel.findViewById(R.id.weixin);
//        ImageView qq = otherLoginRel.findViewById(R.id.qq);
//        wx.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Toast.makeText(context, "微信登录", Toast.LENGTH_SHORT).show();
//            }
//        });

        int X_OFFSET = 0;
        int BOTTOM_OFFSET = 0;
        UnifyUiConfig uiConfig = new UnifyUiConfig.Builder()
                // 状态栏
                .setStatusBarColor(android.R.color.transparent)
                .setStatusBarDarkColor(true)
                // 设置导航栏
//                .setNavigationTitle("一键登录/注册")
//                .setNavigationTitleColor(Color.RED)
//                .setNavigationBackgroundColor(Color.BLUE)
//                .setNavigationIcon("yd_checkbox_checked2")
//                .setNavigationBackIconWidth(25)
//                .setNavigationBackIconHeight(25)
                .setHideNavigation(true)
                //设置背景图片
                .setBackgroundImage("onelogin_bg")
                // 设置logo
                .setLogoIconName("ico_logo")
                .setLogoWidth(87)
                .setLogoHeight(94)
                .setLogoXOffset(X_OFFSET)
                .setLogoTopYOffset(50)
                .setHideLogo(false)
                //手机掩码
                .setMaskNumberColor(Color.WHITE)
                .setMaskNumberSize(22)
                .setMaskNumberTypeface(Typeface.SERIF)
                .setMaskNumberXOffset(X_OFFSET)
                .setMaskNumberTopYOffset(220)
                .setMaskNumberBottomYOffset(BOTTOM_OFFSET)
                // 认证品牌
                .setSloganSize(11)
                .setSloganColor(Color.WHITE)
                .setSloganXOffset(X_OFFSET)
                .setSloganTopYOffset(250)
                .setSloganBottomYOffset(BOTTOM_OFFSET)
                // 登录按钮
                .setLoginBtnText("本机号码一键登录")
                .setLoginBtnTextColor(R.color.login_color_004d80)
                .setLoginBtnBackgroundRes("btn_shape_login_onepass")
                .setLoginBtnWidth(300)
                .setLoginBtnHeight(45)
                .setLoginBtnTextSize(15)
                .setLoginBtnXOffset(X_OFFSET)
                .setLoginBtnTopYOffset(300)
                .setLoginBtnBottomYOffset(BOTTOM_OFFSET)
                // 隐私栏
                .setPrivacyTextStart("我已阅读并同意")
                .setProtocolText("《普育吧用户条款》")
                .setProtocolLink(NetBaseApi.REGISETPROTOCOLURL)
                .setProtocol2Text("《隐私协议》")
                .setProtocol2Link(NetBaseApi.PRIVACYPOLICY)
                .setPrivacyTextEnd("")
                .setPrivacyTextColor(context.getColor(R.color.login_color_b5b5b5))
                .setPrivacyProtocolColor(context.getColor(R.color.login_color_ffcb28))
//                .setHidePrivacyCheckBox(false)
                .setPrivacyTextMarginLeft(25)
                .setPrivacyMarginLeft(X_OFFSET)
                .setPrivacyMarginRight(ScreenUtils.getInstance().dip2px(10))
                .setPrivacyState(true)
                .setPrivacySize(12)
//                .setPrivacyTopYOffset(510)
                .setPrivacyBottomYOffset(20)
                .setPrivacyTextGravityCenter(true)
                .setPrivacyCheckBoxWidth(15)
                .setPrivacyCheckBoxHeight(15)
                .setCheckedImageName("yd_checkbox_checked2")
                .setUnCheckedImageName("yd_checkbox_unchecked2")
                // 协议详情页导航栏
                .setProtocolPageNavTitle("易盾一键登录SDK服务条款")
                .setProtocolPageNavBackIcon("yd_checkbox_checked")
                .setProtocolPageNavColor(Color.BLUE)

//                .setBackgroundImage("bg1")
                // 自定义控件
//                .addCustomView(otherLoginRel, "relative", UnifyUiConfig.POSITION_IN_BODY, null)
//                .addCustomView(closeBtn, "close_btn", UnifyUiConfig.POSITION_IN_TITLE_BAR, new LoginUiHelper.CustomViewListener() {
//                    @Override
//                    public void onClick(Context context, View view) {
//                        Toast.makeText(context, "点击了右上角X按钮", Toast.LENGTH_SHORT).show();
//                    }
//                })
                .addCustomView(textView, "otherlogin", UnifyUiConfig.POSITION_IN_BODY, new LoginUiHelper.CustomViewListener() {
                    @Override
                    public void onClick(Context context, View view) {
                        LoginActivity.startActivity(context);
                    }
                })
                .addCustomView(isagree, "isagree", UnifyUiConfig.POSITION_IN_BODY, new LoginUiHelper.CustomViewListener() {
                    @Override
                    public void onClick(Context context, View view) {
                        isselect = !isselect;
                        isagree.setImageResource(isselect ? com.puyuba.puyuba.R.mipmap.icon_select : com.puyuba.puyuba.R.mipmap.icon_unselect);
                    }
                })
                .build(context);
        return uiConfig;
    }


}
